<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>prefersDarkColorScheme</title>
  </head>
  <body>
    <p>当前是否使用暗黑主题: <span id="text"></span></p>
    <script>
      const prefersDarkColorScheme = () =>
        window &&
        window.matchMedia &&
        window.matchMedia('(prefers-color-scheme: dark)').matches;
      document.querySelector('#text').textContent = prefersDarkColorScheme()
        ? '是'
        : '否';
    </script>
  </body>
</html>
